<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The RecursiveCallbackFilterIterator class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="recursivecachingiterator.haschildren.html">RecursiveCachingIterator::hasChildren</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="recursivecallbackfilteriterator.construct.html">RecursiveCallbackFilterIterator::__construct</a></div>
 <div class="up"><a href="spl.iterators.html">迭代器</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.recursivecallbackfilteriterator" class="reference">

 <h1 class="title">The RecursiveCallbackFilterIterator class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.4.0)</p>


  <div class="section" id="recursivecallbackfilteriterator.intro">
   <h2 class="title">简介</h2>
   <p class="para">

   </p>
  </div>


  <div class="section" id="recursivecallbackfilteriterator.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">RecursiveCallbackFilterIterator</strong>
     </span>
     
     <span class="ooclass">
      <span class="modifier">extends</span>
      <a href="class.callbackfilteriterator.html" class="classname">CallbackFilterIterator</a>
     </span>
     
     <span class="oointerface">implements 
      <span class="interfacename"><a href="class.outeriterator.html" class="interfacename">OuterIterator</a></span>
     </span>

     <span class="oointerface">, 
      <span class="interfacename"><a href="class.recursiveiterator.html" class="interfacename">RecursiveIterator</a></span>
     </span>
     {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><a href="recursivecallbackfilteriterator.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.recursiveiterator.html" class="type RecursiveIterator">RecursiveIterator</a></span> <code class="parameter">$iterator</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$callback</code></span>
   )</div>

    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">RecursiveCallbackFilterIterator</span><span class="methodname"><a href="recursivecallbackfilteriterator.getchildren.html" class="methodname">getChildren</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="recursivecallbackfilteriterator.haschildren.html" class="methodname">hasChildren</a></span>
    ( <span class="methodparam">void</span>
   )</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 继承的方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span><span class="methodname"><a href="callbackfilteriterator.accept.html" class="methodname">CallbackFilterIterator::accept</a></span>
    ( <span class="methodparam">void</span>
   )</div>


   }</div>


  </div>

  
  <div class="section" id="recursivecallbackfilteriterator.examples">
   <h2 class="title">范例</h2>
   <p class="para">
    The callback should accept up to three arguments:
    the current item, the current key and the iterator, respectively.
   </p>
   <div class="example" id="recursivecallbackfilteriterator.examples.args">
    <p><strong>Example #1 Available callback arguments</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Callback&nbsp;for&nbsp;RecursiveCallbackFilterIterator<br />&nbsp;*<br />&nbsp;*&nbsp;@param&nbsp;$current&nbsp;&nbsp;&nbsp;Current&nbsp;item's&nbsp;value<br />&nbsp;*&nbsp;@param&nbsp;$key&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Current&nbsp;item's&nbsp;key<br />&nbsp;*&nbsp;@param&nbsp;$iterator&nbsp;&nbsp;Iterator&nbsp;being&nbsp;filtered<br />&nbsp;*&nbsp;@return&nbsp;boolean&nbsp;&nbsp;&nbsp;TRUE&nbsp;to&nbsp;accept&nbsp;the&nbsp;current&nbsp;item,&nbsp;FALSE&nbsp;otherwise<br />&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">my_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$current</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Your&nbsp;filtering&nbsp;code&nbsp;here<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <p class="para">
    Filtering a recursive iterator generally involves two conditions.
    The first is that, to allow recursion, the callback function should return <strong><code>TRUE</code></strong>
    if the current iterator item has children.
    The second is the normal filter condition, such as a file size or extension 
    check as in the example below.
   </p>
   <div class="example" id="recursivecallbackfilteriterator.examples.basic">
    <p><strong>Example #2 Recursive callback basic example</strong></p>
<div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$dir&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">RecursiveDirectoryIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">__DIR__</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Filter&nbsp;large&nbsp;files&nbsp;(&nbsp;&gt;&nbsp;100MB)<br /></span><span style="color: #0000BB">$files&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">RecursiveCallbackFilterIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">$dir</span><span style="color: #007700">,&nbsp;function&nbsp;(</span><span style="color: #0000BB">$current</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Allow&nbsp;recursion<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$iterator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">hasChildren</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Check&nbsp;for&nbsp;large&nbsp;file<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$current</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isFile</span><span style="color: #007700">()&nbsp;&amp;&amp;&nbsp;</span><span style="color: #0000BB">$current</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSize</span><span style="color: #007700">()&nbsp;&gt;&nbsp;</span><span style="color: #0000BB">104857600</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;<br />});<br />&nbsp;<br />foreach&nbsp;(new&nbsp;</span><span style="color: #0000BB">RecursiveIteratorIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">$files</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getPathname</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>
  

 </div>

 






















<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="recursivecallbackfilteriterator.construct.html">RecursiveCallbackFilterIterator::__construct</a> — Create a RecursiveCallbackFilterIterator from a RecursiveIterator</li><li><a href="recursivecallbackfilteriterator.getchildren.html">RecursiveCallbackFilterIterator::getChildren</a> — Return the inner iterator's children contained in a RecursiveCallbackFilterIterator</li><li><a href="recursivecallbackfilteriterator.haschildren.html">RecursiveCallbackFilterIterator::hasChildren</a> — Check whether the inner iterator's current element has children</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="recursivecachingiterator.haschildren.html">RecursiveCachingIterator::hasChildren</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="recursivecallbackfilteriterator.construct.html">RecursiveCallbackFilterIterator::__construct</a></div>
 <div class="up"><a href="spl.iterators.html">迭代器</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
